package com.yuanfuxing.boxuegu.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.webkit.WebView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.yuanfuxing.boxuegu.R;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

public class WenZiActivity extends AppCompatActivity {
    TextView mTv;
    WebView mCount;
    String title;
    String mycontent;
    RequestParams params = new RequestParams("http://web.csmzxy.com/netCourse/readData");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wen_zi);

        title();
        content();

    }

    public void content() {
        mCount = (WebView) findViewById(R.id.count);
        mycontent = getIntent().getStringExtra("ID");
        RequestParams params1 = new RequestParams("http://web.csmzxy.com/netCourse/readData");
        params1.addQueryStringParameter("cmd", "9");
        params1.addQueryStringParameter("v1", mycontent);
  //      mCount.setMovementMethod(ScrollingMovementMethod.getInstance());
        x.http().get(params1, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                String encoding = "UTF-8";
                String mimeType = "text/html";
                mCount.loadDataWithBaseURL("file://",result,mimeType,encoding,"about:blank");
      //          mCount.setText(Html.fromHtml(result));

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    public void title() {
        mTv = (TextView) findViewById(R.id.tv_text);
        title = getIntent().getStringExtra("ID");
        params.addQueryStringParameter("cmd","41");
        params.addQueryStringParameter("v1",title);
        x.http().get(params, new Callback.CommonCallback<String>() {

            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                ExerciseModel exerciseModel = gson.fromJson(result,ExerciseModel.class);
                if(exerciseModel !=null){
                    title = exerciseModel.contentTitle;
                }
                mTv.setText(title);

            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
    public String convertString(String result) {
        String result1 = result
                .replace(", responseSign : 00", "")
                .replace("\'", "\"")
                .replace("publishurl", "\"publishurl\"")
                .replace("webID", "\"webID\"")
                .replace("webname", "\"webname\"")
                .replace("webitemID", "\"webitemID\"")
                .replace("webitemname", "\"webitemname\"")
                .replace("websubitemname", "\"websubitemname\"")
                .replace("contentID", "\"contentID\"")
                .replace("contentAuthor", "\"contentAuthor\"")
                .replace("contentTitle", "\"contentTitle\"")
                .replace("submitTime", "\"submitTime\"")
                .replace("responseSign", "\"responseSign\"")
                .replace("websubitemID", "\"websubitemID\"");
        return result1;

    }

}
